<template>
  <div>
    <el-dialog
      class="dialog-z"
      title="监考中心"
      v-bind="$attrs"
      v-on="$listeners"
      append-to-body
      :visible.sync="monitoringCenterVisible"
      :close-on-click-modal="false"
      top="5%"
      width="65%"
      @close="close"
    >
      <el-tabs v-model="activeName" @tab-click="operationLogEvent">
        <el-tab-pane label="答题" name="a">
          <div class="father">
            <ul>
              <li
                v-for="item in peopleList"
                :key="item.id"
                @click="monitoringInfo(item, true)"
              >
                <div class="tit">{{ item.stuname }}</div>
                <div class="demo-basic--circle">
                  <img
                    v-if="item.photo"
                    class="headSculpture"
                    :src="item.photo"
                    alt=""
                  />
                  <img
                    v-else
                    class="headSculpture1"
                    src="@/assets/images/head.png"
                    alt=""
                  />
                </div>
                <!-- <div class="foot">
                  <div>
                    <i class="el-icon-circle-close"></i>
                    <span> 0</span>
                  </div>
                  <div>
                    <i class="el-icon-s-operation"></i>
                    <span> 0</span>
                  </div>
                  <div>
                    <i class="el-icon-circle-close"></i>
                    <span> 0</span>
                  </div>
                </div> -->
              </li>
            </ul>
          </div>
        </el-tab-pane>
        <!-- <el-tab-pane label="人脸核身审核" name="b"></el-tab-pane> -->
        <el-tab-pane label="操作日志" name="c" v-loading="listLoading">
          <el-row class="JADP-common-search-box" :gutter="16">
            <el-form @submit.native.prevent>
              <el-col :span="6">
                <el-form-item label="学员名称">
                  <!-- <el-input
                    v-model="query.stuid"
                    placeholder="请输入"
                    clearable
                  >
                  </el-input> -->
                  <el-select
                    v-model="query.stuid"
                    placeholder="请选择"
                    clearable
                  >
                    <el-option
                      v-for="item in stuOptions"
                      :key="item.stuid"
                      :label="item.stuname"
                      :value="item.stuid"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    @click="search"
                    >查询</el-button
                  >
                </el-form-item>
              </el-col>
            </el-form>
          </el-row>
          <el-table
            :data="operationLogList"
            border
            style="margin-top: 20px"
            height="450px"
          >
            <el-table-column label="操作用户" prop="stuid"></el-table-column>
            <el-table-column
              label="操作类型"
              prop="operationtype"
            ></el-table-column>
            <el-table-column
              label="操作内容"
              prop="operationcontent"
            ></el-table-column>
            <!-- <el-table-column label="说明" prop="remark"></el-table-column> -->
            <el-table-column
              label="操作时间"
              prop="operationtime"
            ></el-table-column>
          </el-table>
          <pagination
            :total="total"
            :page.sync="listQuery.currentPage"
            :limit.sync="listQuery.rows"
            @pagination="initData"
          />
        </el-tab-pane>
      </el-tabs>
      <div slot="footer">
        <el-button size="large" plain @click="monitoringCenterVisible = false"
          >取 消</el-button
        >
        <el-button
          type="primary"
          size="large"
          style="margin-right:40px"
          @click="monitoringCenterVisible = false"
          >确 认</el-button
        >
      </div>
    </el-dialog>
    <el-dialog
      :visible="infoVisible"
      v-if="infoVisible"
      title="考生监考详情"
      append-to-body
      top="5%"
      width="60%"
      @close="infoVisible = false"
    >
      <div v-loading="loading">
        <div class="btn">
          <!-- <el-button type="warning" size="large" @click="compulsorySubmission"
            >强制交卷</el-button> -->
          <!-- <el-button type="success" size="large" @click="extendTime"
          >延长考试时长</el-button
        >
        <el-button type="success" size="large">发送提醒消息</el-button> -->
          <el-button type="primary" size="large" @click="checkAnswer"
            >查看作答情况</el-button
          >
          <el-button
            type="info"
            size="large"
            plain
            icon="el-icon-refresh"
            @click="monitoringInfo(item)"
            >{{ refreshTime }}秒后更新信息</el-button
          >
        </div>
        <el-row :gutter="16" class="cont1">
          <el-col :span="12">姓名：{{ dataForm.stuname }}</el-col>
          <el-col :span="12"
            >开始时间：{{
              dayjs(dataForm.starttime).format("YYYY-MM-DD HH:mm:ss")
            }}</el-col
          >
          <!-- <el-col :span="12">未检测到人脸：{{ "0 次" }}</el-col>
        <el-col :span="12">未检测到多个人脸：{{ "0 次" }}</el-col>
        <el-col :span="12">声音超过阈值：{{ "0 次" }}</el-col> -->
          <el-col :span="24">
            <el-divider></el-divider>
            <h3>监控采集的考试画面</h3>
            <h4 v-if="!dataForm.xy_ks_stu_answer_processEntities">
              暂无画面
            </h4>
            <el-row :gutter="10">
              <el-col
                :span="6"
                v-for="item in dataForm.xy_ks_stu_answer_processEntities"
                :key="item.id"
                style="margin-top:10px"
              >
                <img :src="item.snapshots" alt class="tx_img" />
              </el-col>
            </el-row>
            <el-divider></el-divider>
          </el-col>
          <!-- <el-col :span="24">
          <h3>摄像头监控捕捉到异常的画面</h3>
          <h4>暂无画面</h4>
          <el-divider></el-divider>
        </el-col> -->
          <el-col :span="24">
            <h3>切屏记录</h3>
            <el-table
              :data="dataForm.xy_ks_screenRecordsEntities"
              border
              style="margin-top: 20px"
            >
              <el-table-column
                label="切出时间"
                prop="cutouttime"
              ></el-table-column>
              <el-table-column
                label="切回时间"
                prop="cutovertime"
              ></el-table-column>
            </el-table>
            <el-divider></el-divider>
          </el-col>
          <el-col :span="24">
            <h3>操作日志</h3>
            <!-- <el-button type="success" style="margin-top: 10px">导出</el-button> -->
            <el-table
              :data="dataForm.xy_ks_exam_logEntities"
              border
              style="margin-top: 20px"
            >
              <!-- <el-table-column label="操作用户"></el-table-column> -->
              <el-table-column
                label="操作类型"
                prop="operationtype"
              ></el-table-column>
              <el-table-column
                label="操作内容"
                prop="operationcontent"
              ></el-table-column>
              <!-- <el-table-column label="说明" prop="remark"></el-table-column> -->
              <el-table-column
                label="操作时间"
                prop="operationtime"
              ></el-table-column>
            </el-table>
            <!-- <pagination
            :total="total"
            :page.sync="listQuery.currentPage"
            :limit.sync="listQuery.rows"
            @pagination="initData"
          /> -->
            <el-divider></el-divider>
          </el-col>
        </el-row>
        <div slot="footer">
          <el-button type="primary" size="large" style="margin-right:40px">
            确 认
          </el-button>
        </div>
      </div>
    </el-dialog>

    <el-dialog
      title="延长考试时长"
      id="extend-time"
      width="30%"
      top="10%"
      :visible="extendTimeVisible"
      append-to-body
      @close="extendTimeVisible = false"
    >
      <el-row class="extend-time-row">
        <el-col :span="24">
          <span class="sm">延长时间：</span>
          <el-input-number
            v-model="num"
            @change="handleChange"
            :min="1"
            :max="10"
            label="描述文字"
          ></el-input-number>
          <el-input-number
            v-model="num"
            @change="handleChange"
            :min="1"
            :max="10"
            style="margin-left: 20px"
            label="描述文字"
          ></el-input-number>
        </el-col>
        <el-col :span="24">
          <span class="sm">说明：</span>
          <el-input type="textarea" v-model="num" style="width: 80%"></el-input>
        </el-col>
      </el-row>
      <div slot="footer">
        <el-button type="text" @click="extendTimeVisible = false"
          >取 消</el-button
        >
        <el-button
          type="primary"
          @click="extendTimeVisible = false"
          style="margin-right:40px"
          >确 认</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      title="强制交卷"
      id="compulsory-submission"
      width="30%"
      top="10%"
      :visible="compulsorySubmissionVisible"
      append-to-body
      @close="compulsorySubmissionVisible = false"
    >
      <el-row>
        <el-col :span="24">
          <i class="el-icon-info">
            &nbsp;此操作无法撤回,强制交卷后立即结束考生作答，请谨慎操作</i
          >
        </el-col>
        <!-- <el-col :span="24">
          <span class="sm">说明：</span>
          <el-input type="textarea" v-model="num" style="width: 80%"></el-input>
        </el-col> -->
      </el-row>
      <div slot="footer">
        <el-button @click="compulsorySubmissionVisible = false"
          >取 消</el-button
        >
        <el-button
          type="primary"
          @click="compulsorySubmissionBtn"
          style="margin-right:40px"
          >确 认</el-button
        >
      </div>
    </el-dialog>
    <AnswerSituation ref="answerSituation" :dataForm="dataForm" />
  </div>
</template>
<script>
import request from "@/utils/request";
import AnswerSituation from "./answerSituation.vue";
export default {
  name: "",
  components: {
    AnswerSituation
  },
  data() {
    return {
      list: [],
      dataForm: {
        xy_ks_stu_answer_processEntities: []
      },
      num: 0,
      extendTimeVisible: false,
      listLoading: false,
      compulsorySubmissionVisible: false,
      total: 0,
      answerVisible: false,
      monitoringCenterVisible: false,
      query: {
        stuid: ""
      },
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: ""
      },
      activeName: "a",
      infoVisible: false,
      clazzid: "",
      cpid: "",
      stuid: "",
      paperid: "",
      operationLogFlag: true,
      peopleList: [],
      operationLogList: [],
      stuOptions: [], // 学员下拉框
      loading: false,
      refreshTime: 30,
      item: null,
      timer: null //定时器
    };
  },
  watch: {
    infoVisible(val) {
      if (!val) {
        clearInterval(this.timer);
      }
    }
  },

  created() {},

  methods: {
    monitoringInfo(item, flag) {
      if (flag) {
        this.item = item;
      }
      this.infoVisible = true;
      this.loading = true;
      this.stuid = item.stuid;
      this.paperid = item.paperid;
      request({
        url: "/api/screen/Xy_ks_stu_answer_process/" + item.id,
        method: "get"
      }).then(res => {
        this.loading = false;
        this.dataForm = res.data;
        this.refreshTime = 30;
        //先清理上一次的定时器
        clearInterval(this.timer);
        //页面进来先执行一次在延迟1s执行
        this.refreshTime--;
        this.refreshTime < 10
          ? (this.refreshTime = "0" + this.refreshTime)
          : this.refreshTime;
        this.timer = setInterval(() => {
          if (this.refreshTime > 0) {
            this.refreshTime--;
            this.refreshTime < 10
              ? (this.refreshTime = "0" + this.refreshTime)
              : this.refreshTime;
            console.log(this.refreshTime);
          } else {
            clearInterval(this.timer);
            this.monitoringInfo(item);
          }
        }, 1000);
      });
    },
    //操作日志
    operationLogEvent(tab) {
      this.listLoading = true;
      let _query = {
        ...this.listQuery,
        ...this.query
      };
      let query = {};
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join();
        } else {
          query[key] = _query[key];
        }
      }
      if (tab.name == "c" && this.operationLogFlag) {
        request({
          url: "/api/screen/Xy_ks_exam_log",
          method: "get",
          data: {
            ...query,
            cpid: this.cpid,
            clazzid: this.clazzid,
            organizeId:this.$store.getters.organizeId
          }
        }).then(res => {
          this.listLoading = false;
          this.operationLogFlag = false;
          this.operationLogList = res.data.list;
          this.total = res.data.pagination.total;
          console.log(res, 3333333);
        });
        // 请求操作日志学员名称接口
        request({
          url: "/api/scoreManage/Xy_ks_students_score/examLog",
          method: "get",
          data: {
            cpid: this.cpid,
            clazzid: this.clazzid,
            organizeId:this.$store.getters.organizeId
          }
        }).then(res => {
          console.log(res, "人员列表");
          this.stuOptions = res.data;
        });
      }
    },
    compulsorySubmission() {
      this.compulsorySubmissionVisible = true;
    },
    checkAnswer() {
      this.$refs.answerSituation.stuid = this.stuid;
      this.$refs.answerSituation.paperid = this.paperid;
      this.$refs.answerSituation.clazzid = this.clazzid;
      this.$refs.answerSituation.cpid = this.cpid;
      this.$refs.answerSituation.init();
    },
    extendTime() {
      this.extendTimeVisible = true;
    },
    handleChange() {},
    //查询
    search() {
      this.listLoading = true;
      let _query = {
        ...this.listQuery,
        ...this.query
      };
      let query = {};
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join();
        } else {
          query[key] = _query[key];
        }
      }
      request({
        url: "/api/screen/Xy_ks_exam_log",
        method: "get",
        data: {
          ...query,
          cpid: this.cpid,
          clazzid: this.clazzid,
          organizeId:this.$store.getters.organizeId
        }
      }).then(res => {
        this.listLoading = false;
        this.operationLogList = res.data.list;
        this.total = res.data.pagination.total;
        console.log(res, 3333333);
      });
    },

    initData() {
      this.monitoringCenterVisible = true;
      request({
        url: "/api/screen/Xy_ks_stu_answer_process/getList",
        method: "get",
        data: {
          clazzid: this.clazzid,
          cpid: this.cpid,
          organizeId:this.$store.getters.organizeId
        }
      }).then(res => {
        this.peopleList = res.data;
        console.log(this.peopleList, 22);
      });
    },
    //强制交卷
    compulsorySubmissionBtn() {
      request({
        url: "/api/scoreManage/Xy_ks_students_score/end",
        method: "put",
        data: {
          stuid: this.stuid,
          paperid: this.paperid,
          clazzid: this.clazzid,
          cpid: this.cpid
        }
      }).then(res => {
        console.log(res, 11);
        this.$message("强制交卷成功");
      });
    },
    close() {
      this.activeName = "a";
      this.operationLogFlag = true;
    }
  }
};
</script>
<style scoped lang="scss">
>>> .el-dialog__body {
  padding-top: 10px;
}
h4 {
  width: 70px;
  margin: 0 auto;
  color: rgba(0, 0, 0, 0.356);
  line-height: 30px;
}
.btn {
  background: rgb(237, 237, 237);
  padding-left: 20px;
  margin-bottom: 20px;
  line-height: 55px;
}
.father {
  height: 530px;
  overflow: hidden;
  ul {
    width: 101%;
    height: 530px;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    li {
      position: relative;
      width: 20%;
      height: 250px;
      list-style: none;
      margin: 10px 0;
      border: 2px solid rgb(223, 223, 223);
      cursor: pointer;
      background: rgb(252, 252, 252);
      .tit {
        height: 30px;
        background: rgb(246, 246, 250);
        text-align: center;
        line-height: 30px;
      }
      .foot {
        > div {
          margin: 0 35px;
          span {
            font-size: 16px;
          }
        }
        display: flex;
        width: 100%;
        background: #fff;
        justify-content: center;
        align-items: center;
        position: absolute;
        bottom: 0;
        line-height: 30px;
      }
    }
  }
  ul:after {
    content: "";
    /*这个宽度和子元素宽度一致*/
    width: 30%;
    height: 0;
    display: block;
  }
}

.dialog-z ::v-deep .el-dialog__body {
  height: 68vh;
}
#extend-time ::v-deep .el-dialog__body,
#compulsory-submission ::v-deep .el-dialog__body {
  // height: 10vh !important;
  padding-top: 10px;
  .extend-time-row {
    .el-input--small .el-input__inner {
      height: 29px;
      line-height: 32px;
    }
    line-height: 50px;
    .el-col {
      padding-bottom: 2px;
      .el-icon-info {
        margin-left: 38px;
      }
    }
    .sm {
      display: inline-block;
      width: 65px;
      text-align: right;
    }
  }
}
.headSculpture {
  width: 100%;
  height: 215px;
}
.headSculpture1 {
  width: 128px;
  margin-left: 10%;
  position: relative;
  left: 50%;
  margin-left: -64px;
  margin-top: 20px;
}
.el-icon-s-operation {
  transform: rotate(90deg);
  transform: translateY(0.5px);
  top: -2px;
}
.cont1 {
  line-height: 25px;
  font-size: 13px;
  padding-left: 20px;
  height: 500px;
  overflow-y: auto;
  .tx_img {
    width: 200px;
    height: 200px;
  }
}
</style>
